/**
 * a pattern is one or more music measures representing a loopable music part. this is used for describe existing measures or creating loopable
 * music by algorithm
 * @deprecated this prototype class is not used any more
 */
jweb.util.MusicPattern = function(params) {
	function cleanArg(key, defautValue) {
      return (params[key] != null && params[key] != "") ? params[key] : defautValue;
	}
	/*how many beats*/
	this.beats = 4;
	/*name of pattern */
	this.name ='demo1';
	/*notes*/
	this.midiMessages =[];
}
jweb.util.MusicPattern.prototype= {
	/**
	 * notes parameter is one array of objects describing notes which will generate note on/off midi messages.
	 * It is not your responsibility to compute offset, please leave ZERO there, the system will correct latency when playing.
	 * relative time offset is stored there.
	 * type is the index of fast note time duration index in
	 * this.fastNoteTimes = [secPerBeat*4, secPerBeat*2, secPerBeat, secPerBeat/2, secPerBeat/4, secPerBeat/8];
	 * sample data:
	 * [
	 * {midi:[29, 100, 64],type:2}
	 * ]
	 */
	setMidiMessages:function(nt){
		this.midiMessages = nt;
	},
	setName:function(n){
		this.name=n;
	},
	setBeats:function(b){
		this.beats = b;
	}
}
/**
 * the pattern was designed by Huang Xu. @see etc/P1 and P2
 * data structure description: each note in one array is length of 4 [midivalue, velocity, fastNoteTimeIndex]
 */
var stayHot = {beats:4, 
			name:'Mad Heart',
		 m:[
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[52,100, 4, 1],min:[51,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    
		    {maj:[53,100, 4, 1],min:[51,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[52,100, 4, 1],min:[50,100, 4, 1],bass:[24, 100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[0, 0, 4, 1]},
		    
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[52,100, 4, 1],min:[51,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    
		    {maj:[53,100, 4, 1],min:[51,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[52,100, 4, 1],min:[50,100, 4, 1],bass:[24, 100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[0, 0, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[0, 0, 4, 1]}
		 ]};
var madHeart = {beats:4, 
		 name:'Mad Heart',
		 m:[
		    {maj:[36,100, 4, 1],min:[36,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[39,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[41,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[44,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[41,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[39,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[36,100, 4, 1],min:[24,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[36,100, 4, 1],min:[36,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[39,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[41,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[44,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[41,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[39,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[36,100, 4, 1],min:[24,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]}
		 ]};
var chn1 ={beats:4, 
		 name:'CHN Demo',
		 m:[
		    {maj:[24,100, 2, 1],min:[24,100, 2, 1],bass:[24,100, 2, 1]},
		    //C4
		    {maj:[60,100, 4, 1],min:[60,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[55,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[45,100, 4, 1],min:[46,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[52,100, 4, 1],min:[53,100, 4, 1],bass:[24,100, 4, 1]},
		    //G3
		    {maj:[55,100, 4, 1],min:[55,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[50,100, 4, 1],min:[51,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[41,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    //D3
		    {maj:[50,100, 4, 1],min:[51,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[45,100, 4, 1],min:[46,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[36,100, 4, 1],min:[36,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    //A2
		    {maj:[45,100, 4, 1],min:[46,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[36,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[52,100, 4, 3],min:[53,100, 4, 3],bass:[24,100, 4, 3]},
		    //G3
		    {maj:[55,100, 4, 1],min:[55,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[45,100, 4, 1],min:[46,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[21,100, 4, 1],min:[22,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[52,100, 4, 1],min:[53,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[33,100, 4, 1],min:[34,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[57,100, 4, 1],min:[58,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[19,100, 4, 1],min:[19,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[55,100, 4, 1],min:[55,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]}
		 ]};
var ele1 ={beats:4, 
		 name:'Electro Demo',
		 m:[
		    {maj:[24,100, 4, 1],min:[24,100, 4, 1],bass:[24,100, 2, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[40,100, 4, 1],min:[39,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[64,100, 4, 1],min:[63,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[55,100, 4, 1],min:[55,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[67,100, 4, 1],min:[67,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[0,100, 3, 1],min:[0,100, 3, 1],bass:[24,100, 3, 1]},
		    //c5
		    {maj:[72,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[55,100, 4, 1],min:[55,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[24,100, 4, 1],min:[24,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[64,100, 3, 1],min:[63,100, 3, 1],bass:[24,100, 3, 1]},
		    
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[0,100, 4, 1],min:[0,100, 4, 1], bass:[0,100, 4, 1]},
		    {maj:[62,100, 3, 1],min:[62,100, 3, 1],bass:[24,100, 3, 1]},
		    
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[64,100, 4, 1],min:[63,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[36,100, 4, 1],min:[36,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[48,100, 4, 1],min:[48,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[62,100, 4, 1],min:[62,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[60,100, 4, 1],min:[60,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[31,100, 4, 1],min:[31,100, 4, 1],bass:[24,100, 4, 1]},
		    
		    {maj:[59,100, 4, 1],min:[58,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[50,100, 4, 1],min:[50,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[60,100, 4, 1],min:[60,100, 4, 1],bass:[24,100, 4, 1]},
		    {maj:[43,100, 4, 1],min:[43,100, 4, 1],bass:[24,100, 4, 1]}
		 ]};
var allPatterns = [stayHot, madHeart, ele1, chn1];